package cn.wolfcode.luowowo2.mgrsite.web.controller;

import cn.wolfcode.luowowo2.article.domain.Strategy;
import cn.wolfcode.luowowo2.article.service.IDestinationService;
import cn.wolfcode.luowowo2.article.service.IStrategyService;
import cn.wolfcode.luowowo2.common.query.QueryObject;
import cn.wolfcode.luowowo2.common.query.StrategyQueryObject;
import cn.wolfcode.luowowo2.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Albert on 2019/7/9.
 */
@Controller
@RequestMapping("strategy")
public class StrategyController {
    @Reference
    private IStrategyService strategyService;

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("list")
    public String list(Model model, StrategyQueryObject qo){
        PageInfo<Strategy> pageInfo = strategyService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("dests",destinationService.getDestByDeep(3));
        return "strategy/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(Strategy strategy){
        strategyService.saveOrUpdate(strategy);
        return new AjaxResult();
    }
}
